/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       buffer_window.cpp

	$Header: /game/buffer_window.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "buffer_window.h"

#include "convert_16_bit.h"
#include "paint_surface.h"

t_image_buffer::t_image_buffer()
{
}

t_image_buffer::t_image_buffer( t_image_buffer const& arg ) : m_bitmap( arg.m_bitmap )
{
}

t_image_buffer::~t_image_buffer()
{
}

t_image_buffer& t_image_buffer::operator=( t_image_buffer const& arg )
{
	m_bitmap = arg.m_bitmap;
	return *this;
}

// ----------------------------------------------------------------------
// wrapper to hide details of dib section
// ----------------------------------------------------------------------
t_image_buffer::t_image_buffer( int width, int height )
	: m_bitmap( new t_memory_bitmap16( width, height ) )
{
}

// ----------------------------------------------------------------------
// wrapper to hide details of dib section
// ----------------------------------------------------------------------
t_abstract_bitmap16* t_image_buffer::get_bitmap() const
{
	return m_bitmap.get();
}

// ----------------------------------------------------------------------
// window which displays a bitmap buffer
// ----------------------------------------------------------------------
t_buffer_window::t_buffer_window( t_screen_point point, t_window* parent )
	: t_window( t_screen_rect( point.x, point.y, point.x, point.y), k_no_transparency, parent )
{
}

// ----------------------------------------------------------------------
// window which displays a bitmap buffer
// ----------------------------------------------------------------------
void t_buffer_window::set_bitmap( t_image_buffer const& bitmap )
{
	if (bitmap.get_bitmap() == m_bitmap.get_bitmap())
		return;

	m_bitmap = bitmap;
	move_screen_rect( get_screen_rect().top_left() + bitmap.get_bitmap()->get_rect() );
	invalidate();
}

// ----------------------------------------------------------------------
// window which displays a bitmap buffer
// ----------------------------------------------------------------------
void t_buffer_window::paint( t_paint_surface& paint_surface )
{
	paint_surface.draw( t_screen_point(0,0), *m_bitmap.get_bitmap(), m_bitmap.get_bitmap()->get_rect() );
}
